package com.neusoft.neuiotms.dcvm.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.bizcore.web.dto.result.ResultListDTO;
import com.neusoft.neuiotms.dcvm.enums.DictionaryType;
import com.neusoft.neuiotms.dcvm.model.Dictionary;
import com.neusoft.neuiotms.dcvm.repository.DictionaryRepository;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api("字典管理")
@RestController
@RequestMapping(value = "/api/w/dictionaries")
public class DictionaryController {

    @Autowired
    private DictionaryRepository dictionaryRepository;

    @ApiOperation("查询字典项")
    @GetMapping
    public ResultListDTO<Dictionary> index() {
        final List<Dictionary> allModels = this.dictionaryRepository.findAll();
        return ResultListDTO.success(allModels);
    }

    @ApiOperation("查询字典项")
    @GetMapping("/{type}")
    public ResultListDTO<Dictionary> index(@PathVariable final String type) {
        final List<Dictionary> allModels = this.dictionaryRepository.findAllByType(DictionaryType.valueOf(type));
        return ResultListDTO.success(allModels);
    }
}
